package com.xy.test.service.impl;

import com.xy.test.feign.MyFeignClient;
import com.xy.test.mapper.OrderMapper;
import com.xy.test.service.OrderService;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private MyFeignClient feignClient;

    @Autowired
    private OrderMapper mapper;

    @GlobalTransactional
    public Integer createOrder(Integer productId) {

        System.out.println("seata全局事务id====================>"+ RootContext.getXID());
        feignClient.desc(productId);

        Integer res =  mapper.createOrder(productId);
        int i = 100 / productId;
        return res;
    }

    @GlobalTransactional
    public Integer createTccOrder(Integer productId) {

        System.out.println("seata全局事务id====================>"+ RootContext.getXID());
        feignClient.tccDesc(productId);

        Integer res =  mapper.createOrder(productId);
        int i = 100 / productId;
        return res;
    }
}
